<template>
	<div class="back_contain_n mine-account">
		<div class="mainTable">
			<!-- 头部搜索 -->
			<div class="Search_Top_Part">
				<div class="search_list" >
					<div>
						<div class="input_flex daterange">
							<el-date-picker v-model="time"
								type="daterange"
								range-separator="-"
								start-placeholder="开始日期"
								end-placeholder="结束日期">
							</el-date-picker>
						</div>
					</div>
				</div>
				<div class="search_bt">
					<span class="zll-search" @click="getList()">搜索</span>
					<span class="zll-search-reset" @click="searchReset()">重置</span>
				</div>
			</div>
			<!-- table -->
			<sys-table
				ref="systable"
				:isMultipleSelection="false"
				:tableData="tableData"
				:tableLoading="tableLoading"
				:tableHeader="tableHeader"
				:scopeWidth="120"
				:backCount="backCount"
				@getBackData="getList"
			>
				<template slot-scope="scope" slot="operate">
					<el-button @click="edit(scope.row,'see')" type="text" size="small">查看</el-button>
				</template>
			</sys-table>
			
			<!---- 弹框-------->
			<div class="zll-dialog">
				<popout title="当班计件及出勤 · 查看" :visible.sync="addDialog" v-if="addDialog" class="bg_maxSize">
					<add ref="add" slot="content" :type="type" :editData="editData"></add>
					<template slot="bottom">
						<p class="zll-botton Info" @click="addDialog = false">关 闭</p>
					</template>
				</popout>
			</div> 
        </div>
	</div>
</template>

<script>
 	import Add from './add.vue'
	import {formatDate} from "@/plugins/formatDate";

    export default {
        data(){
            return {
				tableLoading: true, //table刷新
				type: '',
				editData: {},

				queryForm: {
					bgStatus: '',
					userId: '',
				},
				backCount: 0,
				tableData: [],
				tableHeader: [],
				addDialog: false,
				time:[]
            }
        },
        methods: {

			edit(val, type) {
				let self = this;
				self.addDialog = true;
				self.type = type;
				self.$nextTick(() => {
					self.editData = Object.assign({}, val);
				});
			},

			getList(startIndex, pageRow) {
				let self = this;
				self.tableLoading = true;
				if (this.time && this.time.length == 2) {
					//date类型
					self.queryForm.startTime = formatDate(new Date(self.time[0]), 'yyyy-MM-dd')
					self.queryForm.endTime = formatDate(new Date(self.time[1]), 'yyyy-MM-dd') + ' 23:59:59'
				} else {
					self.queryForm.startTime = '';
					self.queryForm.endTime = '';
				}
				let pageInfo = self.$refs.systable.getPageInfo(startIndex);
				if (pageInfo.pageNum == 0||startIndex == 0) {
					self.$refs.systable.resetPage();
				}
				self.queryForm.startIndex = pageInfo.pageNum;
				self.queryForm.totalPage = pageInfo.pageSize;
				let param = Object.assign({}, self.queryForm);
				param.resver = '1';
				self.$http({
					url: "/jinl/bg/getOnDutyBgList",
					method: "post",
					params:param
				}).then(resp => {
					if (resp.success) {
						self.tableLoading = false;
						self.tableData = resp.result;
						self.tableHeader = [
							{"columnValue": "dutyDay", "columnName": "日期" },
							{"columnValue": "totalUserCount", "columnName": "总人数" },
							{"columnValue": "whiteUserCount", "columnName": "生产白班"},
							{"columnValue": "blackUserCount", "columnName": "生产夜班"},
							{"columnValue": "buQuanUserCount", "columnName": "补全人数" },
							{"columnValue": "chuqinTotalUser", "columnName": "非生产"},
							{"columnValue": "checkUserName", "columnName": "核定人"},
							{"columnValue": "checkTime", "columnName": "核定日期"},
						];
						if (resp.result.length > 0) {
							self.backCount = resp.result[0].count;
						} else {
							self.backCount = 0;
						}
						if(self.viewType == '0'){
							self.paramList[0].num = self.backCount;
						}
					}
				});

			},


			searchReset() { //重置搜索
				this.queryForm = {
					bgStatus: '',
					userId: '',
				};
				this.time = [];
				this.getList();
			},

		},
        mounted(){
			let self = this;
            self.getList();
        },
        components: {
            Add
        },
    }
</script>

<style lang="scss" scoped>
	@import "@/style/SearchTop.scss";

	.mine-account {
		.search_list {
			display: flex;
			justify-content: space-between;
		}

		.leftList {
			display: flex;
			margin-bottom: 15px;

			li {
				list-style: none;
				width: 100px;
				height: 30px;
				line-height: 28px;
				border-bottom: 1px solid #fff;
				color: #333;
				text-align: center;
				cursor: pointer;
				margin-bottom: 10px;
				transition: all .5s;
				position: relative;
				display: flex;
				justify-content: center;

				&.active {
					color: #ff9935;
					border-color: #ff9935;
					position: relative;
					font-weight: 600;
					font-size: 14px;
				}

				.nums {
					position: absolute;
					right: 5px;
					top: 0;
					background: #f44336;
					color: #fff;
					height: 16px;
					line-height: 16px;
					font-weight: 400;
					border-radius: 8px;
					font-size: 12px;
					padding: 0 5px;
				}
			}
		}
	}
</style>
